package com.lixn.homework.controller;

import com.lixn.homework.pojo.Article;
import com.lixn.homework.service.ArticleService;
import com.lixn.homework.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class MyController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/toIndex")
        public String index(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                        @RequestParam(value = "pageSize", defaultValue = "2", required = false) Integer pageSize, Model model) throws Exception {
        PageUtils<Article> byCondition = articleService.findByCondition(pageNum, pageSize);
        model.addAttribute("data", byCondition);
        return "index";
    }
}
